#include "../include/process_management.h"

/* variable local to this module, gives the next pid */
int next_pid = 0;

/* function bodies */

void initialize_processes_table(){
	int i;
	for(i=0;i<NUMBER_MAX_PROCESSES;i++)
		processes[i].in_use = 0; //we mark this PCB as being unused
}

uint32_t create_process(uint32_t priority){
	int i;
	uint32_t pid = 0; 
	for(i=0;i<NUMBER_MAX_PROCESSES;i++)
		if(!processes[i].in_use){
			pid = next_pid;
			next_pid ++;
			processes[i].in_use = 1; //this PCB is now used by a process
			processes[i].pid = pid;
			processes[i].priority = priority;
			break; 
		}
	return pid;
}

void remove_process(uint32_t pid){
	int i;
	for(i=0;i<NUMBER_MAX_PROCESSES;i++)
		if(processes[i].in_use && processes[i].pid == pid)
			processes[i].in_use = 0; //this PCB is no longer used
}
